<template>
  <el-container>
    <el-header>
      <div>
        <img class="home-head-img" src="../assets/img/head.jpg"/>
        <span>电商后台管理系统</span>
      </div>
      <div>
        <el-button type="danger" round @click="logout">exit</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse?'64px':'200px'">
        <div class="toggle-button" @click="isCollapse=!(isCollapse)">| | |</div>
        <el-menu
            router
            :collapse="isCollapse"
            :collapse-transition="false"
            unique-opened
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409eff">
          <el-submenu :index="' '+item.id" v-for="(item ,index) in menus" :key="item.id">
            <template #title>
              <!--图标-->
              <i :class="icon_obj[item.id]"></i>
              <!--文本-->
              <span>{{ item.authName }}</span>
            </template>
            <el-menu-item
                :index="'/'+item1.path"
                :key="item1.id"
                v-for="item1 in item.children">
              <template #title>

                <!--图标-->
                <i class="el-icon-menu"></i>
                <!--文本-->
                <span>{{ item1.authName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-main>
        <router-view></router-view>
      </el-main>
      <!--      <el-footer>Footer</el-footer>-->
    </el-container>
  </el-container>


</template>

<script>
import axios from "axios";

export default {
  name: "Home",
  created() {
    this.getMenus()
  },
  data() {
    return {
      isCollapse: false,
      menus: [],
      icon_obj: {
        '125': 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao',
      }
    }
  }, methods: {
    async getMenus() {
      const {data} = await axios.get('menus')
      console.log(data)
      if (data.meta.status !== 200) return this.$message.error(data.meta.msg)

      this.menus = data.data
      console.log(this.menus)
    },
    logout() {
      window.window.sessionStorage.clear();
      this.$router.push('/login')
    }
  }
}
</script>

<style lang="less" scoped>

.home-head-img {
  margin-left: 15px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.el-container {
  height: 100%;
}

.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  padding-right: 0;

  //align-content: center;
  color: #ffffff;
  font-size: 20px;

  > div {
    display: flex;
    align-items: center;

    span {
      margin-left: 15px;
    }
  }
}

.el-aside {
  background-color: #333744;

  .el-menu {
    border-right: none;
    //margin-right: 20px;
  }

  .el-menu-item {
    text-align: center;
    line-height: 56px;
    height: 56px;
    padding-left: 0;
  }

  .toggle-button {
    color: #eeeeee;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
  }
}

.el-main {
  background-color: #eaedf1;
}

.iconfont {
  margin-right: 20px;
}

//.el-submenu{
//  padding-left: 0;
//}
</style>